var util = require('../../utils/util.js');
var status = require('../../utils/index.js');
var a = require("../../utils/public");
var countDownInit = require("../../utils/countDown");
var wcache = require('../../utils/wcache.js');
var app = getApp();
var timerOut = '';

Page({
    mixins: [require('../../mixin/globalMixin.js')],
    data: {
        indicatorDots: true,
        autoplay: false,
        interval: 2000,
        duration: 500,
        pageNum: 1,
        loadMore:true,
        showEmpty:false,
        swiperlist:[],//轮播图
        rushList:[],//店铺列表
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        // wx.showLoading();
        // wx.hideTabBar();
        this.loadPage();
    },
    loadPage: function () {
        console.log(11);
        this.load_goods_data();
    },
    load_goods_data: function () {
        var token = wx.getStorageSync('token');
        var that = this;
        var cur_community = wx.getStorageSync('community');
        console.log('load_goods_begin ');
        
        app.util.request({
            'url': 'entry/wxapp/index',
            'data': {
                controller: 'index.load_gps_supplierlist',
                token: token,
                pageNum: that.data.pageNum,
                head_id: cur_community.communityId,
                per_page: 8
            },
            dataType: 'json',
            success: function (res) {
                if (that.data.pageNum == 1) {
                    that.setData({ cate_info: res.data.cate_info || {} })
                }
                if (res.data.code == 1) {
                    console.log(res.data);
                    if (res.data.list.length == 8){
                        that.setData({
                            loadMore: true
                        });
                    }else{
                        that.setData({
                            loadMore: false
                        });
                    }
                    var rushList = that.data.rushList.concat(res.data.list);
                    that.setData({
                        swiperlist: res.data.swiperlist,
                        rushList: rushList
                    })
                    if (that.data.pageNum == 1 && that.data.rushList.length == 0){
                        that.setData({
                            showEmpty: true
                        })
                    }
                    console.log(rushList);
                }
            },
            complete: function () {
                // wx.hideLoading();
                setTimeout(function () { wx.hideLoading(); }, 1000);
            }
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let that = this;
        this.setData({ tabbarRefresh: true })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {
        this.setData({
            tabbarRefresh: false
        })
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        console.log("lionfish_comshop/pages/type/supplier");
        return {
            path: "lionfish_comshop/pages/type/supplier",
            success: function () { },
            fail: function () { }
        };
    },
    onReachBottom: function () {
        var that = this;
        if(that.data.loadMore){
            var pageNum = that.data.pageNum
            pageNum++;
            that.setData({
                pageNum: pageNum
            })
            this.load_goods_data();
        }
    },
    goshop: function (e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/lionfish_comshop/pages/type/shopinfo?id=' + id,
        })
    },
    goDetail: function (e) {
        let idx = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/lionfish_comshop/pages/goods/goodsDetail?&id=' + idx,
        })
    }
})